package com.swordxu.yim.server.memcache;

import com.esotericsoftware.kryo.Kryo;
import com.swordxu.yim.server.utils.KryoRedisSerializer;
import redis.clients.jedis.Jedis;

/**
 * Created by user063 on 2015/1/5.
 */
public class SessionCache {
    private static Jedis jedis;

    public static Jedis getInstance() {
        if (jedis == null) {
            jedis = new Jedis("192.168.59.103");
        }

        return jedis;
    }

    public static void insert(String key, Object obj) {
        getInstance().set(key.getBytes(), KryoRedisSerializer.serialize(obj));
    }

    public static Object read(String key) {
        return KryoRedisSerializer.deSerialize(SessionCache.getInstance().get(key.getBytes()));
    }

    public static void main(String args[]) {
        Jedis jedis = new Jedis("192.168.59.103");
        jedis.set("foo", "bar");
        String value = jedis.get("foo");

        System.out.println(value);
    }
}
